<?php
declare (strict_types = 1);

namespace app\api\controller\Product;

use app\BaseController;
use app\common\model\Product\Product as ProductModel;
use think\Request;

class Product extends BaseController
{
    public function index()
    {
        $typeid = $this->request->param('typeid');

        $flag=$this->request->param('flag');
        $OrderBy=$this->request->param('OrderBy');
        // 条件数组
        $where = [];

        if($typeid)
        {
            $where['typeid'] = $typeid;
        }
        if($flag)
        {
            $where['flag'] = $flag;
        }

        $ProductList = ProductModel::where($where)->order($OrderBy,'desc')->select();

        if(!$ProductList)
        {
            $this->error('暂无商品');
        }

        $this->success('查询成功',null,$ProductList);

    }
    public function info()
    {
        $proid = $this->request->param('proid');

        $product = ProductModel::find($proid);

        if(!$product)
        {
            $this->error('商品不存在，请重新选择');
        }

        $this->success('查询成功',null,$product);
    }
}
